// pages/car/car.js
Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		http: getApp().globalData.map
	},

	/**
	 * 生命周期函数--监听页面加载
	 */
	onShow: function(options) {
		this.res()
	},
	res() {
		wx.getStorage({
			key: 'uid',
			success: (env) => {
				wx.request({
					url: getApp().globalData.http + 'action=myCarList&uid=' + env.data.uid,
					success: (e) => {
						console.log(e)
						if (e.data.data.length > 0) {
							wx.setStorage({
								key: 'car',
								data: e.data.data,
							})
						} else {
							wx.setStorage({
								key: 'car',
								data: '',
							})
						}
						this.setData({
							data: e.data.data,
							uid: env.data.uid
						})
					}
				})
			},
			fail: () => {
				wx.redirectTo({
					url: '../register/register'
				})
			}
		})
	},
	// action=setCarMr、carid=车辆ID
	moren(e) {
		wx.request({
			url: getApp().globalData.http + 'action=setCarMr&carid=' + e.currentTarget.dataset.id + '&uid=' + this.data.uid,
			success: (e) => {
				console.log(e)
				this.res()
			}
		})
	},
	delet(e) {
		wx.request({
			url: getApp().globalData.http + 'action=delCarInfo&carid=' + e.currentTarget.dataset.id + '&uid=' + this.data.uid,
			success: (e) => {
				console.log(e)
				this.res()
			}
		})
	},
	nav(e) {
		wx.navigateTo({
			url: 'baoyang/baoyang?id=' + e.currentTarget.dataset.id
		})
	}
})
